package br.com.appweb.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.appweb.javabeans.Circulo;

public class CirculoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public CirculoServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.processaRequisicao(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.processaRequisicao(request, response);
	}

	public void processaRequisicao(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//Pegando os parametros vindos do request
		double raio = Double.parseDouble(request.getParameter("raio"));
		
		//Criando o objeto Circulo
		Circulo circulo = new Circulo();
		
		//Setando os valores do objeto Circulo
		circulo.setRaio(raio);
		
		//Incluindo o objeto Circulo no request
		request.setAttribute("circuloBEAN", circulo);
		
		//Redirecionamento
		RequestDispatcher view = request.getRequestDispatcher("resultado.jsp");
		
		//Passando os objetos para a view
		view.forward(request, response);
	}
}
